import axios from 'axios';

// 获取单据列表
export function getBillList(param) {
    return axios({
        method: 'post',
        url: '/billView/queryList',
        data: param,
        headers: {
            'Cache-Control': 'no-cache'
        }
    })
}

//获取制单人列表
export function getCreators(param) {
    return axios({
        method: 'get',
        url: '/billView/getUserRefList',
        params: param,
        headers: {
            'Cache-Control': 'no-cache'
        }
    })
}

//获取组织信息
export function getOrgUrl(param) {
    return axios({
        method: 'get',
        url: '/organization/getPermOrgByUser',
        params: param,
        headers: {
            'Cache-Control': 'no-cache'
        }
    })
}

//获取项目信息
export function getProList(param) {
    return axios({
        method: 'get',
        url: '/billView/queryPermProjects',
        params: param,
        headers: {
            'Cache-Control': 'no-cache'
        }
    });
}

//单据预览 已废弃
export function getPrintCode(param) {
    return axios({
        method: 'get',
        url: '/bo/getPrintCode',
        params: param,
        headers: {
            'Cache-Control': 'no-cache'
        }
    })
}

//单据预览2019022版
export function getPrintCodeByType(param) {
    return axios({
        method: 'get',
        url: '/bo/getPrintCodeByType',
        params: param,
        headers: {
            'Cache-Control': 'no-cache'
        }
    })
}

//亿嘉和专项导出接口
export function getSpecialExport(params) {
    return axios({
        method: 'post',
        url: 'billView/export',
        data: params,
        headers: {
            'Cache-Control': 'no-cache'
        },
        responseType: 'arraybuffer' // 后台返回的数据流，必须设置该字段，要不然会乱码的哦
    })
}

//获取boCode
export function getBoCode(param) {
    return axios({
        method: 'get',
        url: '/billView/getBusiObjectCode',
        params: param,
        headers: {
            'Cache-Control': 'no-cache'
        }
    })
}

// 单据类型
export const BillTypeList = [
    { key: "KGBG", value: "开工报告", isApproval: true },
    { key: "AQZG", value: "安全整改", isApproval: true },
    { key: "XCJL", value: "巡查记录", isApproval: false },
    { key: "PZJL", value: "旁站记录", isApproval: false },
    { key: "PXJY", value: "平行检验", isApproval: false },
    { key: "SGJL", value: "施工记录", isApproval: true },
    { key: "GXBY", value: "工序报验", isApproval: true },
    { key: "WTJL", value: "问题记录", isApproval: false },
    { key: "GXPZ", value: "工序拍照", isApproval: true },
    { key: "GZLX", value: "工作联系", isApproval: false },
    { key: "BGQZ", value: "签证申请", isApproval: true },
    { key: "BGSQ", value: "变更申请", isApproval: true },
    { key: "SGRZ", value: "施工日志", isApproval: true },
    { key: "ZHYS", value: "综合验收", isApproval: true },
    { key: "TGBG", value: "停工单", isApproval: true },
];

// 审批状态
export const BillStatusList = [
    { key: "7", value: "审批中" },
    { key: "8", value: "已驳回" },
    { key: "9", value: "审批通过" }
];

// 获取对应状态
export function getBillStatusText(billStatus) {
    let billStatusText = "";
    switch (billStatus) {
        case 0:
            billStatusText = "待整改";
            break;
        case 1:
            billStatusText = "待验收";
            break;
        case 2:
            billStatusText = "已关闭";
            break;
        case 3:
            billStatusText = "整改记录-初始态";
            break;
        case 4:
            billStatusText = "整改记录-通过";
            break;
        case 5:
            billStatusText = "整改记录-不通过";
            break;
        case 7:
            billStatusText = "审批中";
            break;
        case 8:
            billStatusText = "已驳回";
            break;
        case 9:
            billStatusText = "审批通过";
            break;
        default:
            break;
    }
    return billStatusText;
}

// 是否超期
export function isOverTime(text) {
    if (text) {
        return "超期";
    } else {
        return "未超期";
    }
}

// 根据不同单据类型获取请求参数
export function getDiffReq(type, param) {
    let postData = null;
    switch (type) {
        // 开工报告
        case "KGBG":
            postData = {
                billType: type,
                pkBill: param.pkWorkstartreport
            }
            break;
        // 安全整改
        case "AQZG":
            postData = {
                billType: type,
                pkBill: param.pkSafetyRectification
            }
            break;
        // 巡查记录
        case "XCJL":
            postData = {
                billType: type,
                pkBill: param.pk_siteinspection
            }
            break;
        // 旁站记录
        case "PZJL":
            postData = {
                billType: type,
                pkBill: param.pk_siteinspection
            }
            break;
        // 平行检验
        case "PXJY":
            postData = {
                billType: type,
                pkBill: param.pk_siteinspection
            }
            break;
        // 施工记录
        case "SGJL":
            postData = {
                billType: type,
                pkBill: param.pk_constructionlog
            }
            break;
        // 工序报验
        case "GXBY":
            postData = {
                billType: type,
                pkBill: param.pk_process_inspect
            }
            break;
        // 问题记录
        case "WTJL":
            postData = {
                billType: type,
                pkBill: param.pk_problem
            }
            break;
        // 工序拍照
        case "GXPZ":
            postData = {
                billType: type,
                pkBill: param.pkProcessphoto
            }
            break;
        // 工作联系
        case "GZLX":
            postData = {
                billType: type,
                pkBill: param.pk_workconnect
            }
            break;
        // 变更签证
        case "BGQZ":
            postData = {
                billType: type,
                pkBill: param.pkAlterandvisa
            }
            break;
        // 变更申请
        case "BGSQ":
            postData = {
                billType: type,
                pkBill: param.pkAlter
            }
            break;
        // 施工日志
        case "SGRZ":
            postData = {
                billType: type,
                pkBill: param.pkConstructiondiary
            }
            break;
        // 综合验收
        case "ZHYS":
            postData = {
                billType: type,
                pkBill: param.pkComprehensiveAcceptance
            }
            break;
        // 停工单
        case "TGBG":
            postData = {
                billType: type,
                pkBill: param.pkWorkstopreport
            }
            break;
        default:
            break;
    }
    return postData;
}

//解决select组件设置为多选时，下拉箭头消失问题
export function fixMuliSelectArrow(nodeArr) {
    for (let i = 0; i < nodeArr.length; i++) {
        let arrowHTML = document.createElement("span");
        arrowHTML.innerHTML = '<b></b>';
        arrowHTML.className = 'u-select-arrow';
        nodeArr[i].appendChild(arrowHTML);
    }
}

//解决在didMount中添加的相关node节点
export function clearAddedNode() {
    // 移除多选下拉框后方箭头node节点
    let multipleSelectArr = document.getElementsByClassName('u-select-selection--multiple');
    for (let i = 0; i < multipleSelectArr.length; i++) {
        multipleSelectArr[i].removeChild(multipleSelectArr[i].lastElementChild);
    }

}